<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const maxSubArray = (nums) => {
            var k = 0, ans = 0;n = nums.length;
            for (let j = 0; j < nums.length; j++) {
                ans = Math.min(ans, nums[j])
            }
            while (k <= n) {
                if (k > 0) {
                    nums.shift()
                }
                var sum = 0
                for (let i = 0; i < nums.length; i++) {
                    sum += nums[i]
                    ans = Math.max(sum, ans)
                }
                k++
            }
            return ans
        }
        console.log(maxSubArray([-1, -2, -3, 0]));
    </script>
</body>

</html>